﻿


<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-collapse" lay-accordion="">
                        <div class="layui-colla-item">
                            <h2 class="layui-colla-title">筛选查询</h2>
                            <div class="layui-colla-content layui-show">
                                <div class="layui-card">
                                    <form class="layui-form" lay-filter="AutoCodeSearchForm" id="AutoCodeSearchForm" autocomplete="off">
                                        <div class="layui-form-item">
                                            <div class="layui-inline">
                                                <label class="layui-form-label">表名称：</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="tbName" placeholder="表名称" class="layui-input">
                                                </div>
                                            </div>
                                            <div class="layui-inline">
                                                <label class="layui-form-label">表描述：</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="tbDes" placeholder="表描述" class="layui-input">
                                                </div>
                                            </div>
                                            <div class="layui-inline">
                                                <label class="layui-form-label">实体名：</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="tbModelName" placeholder="实体名" class="layui-input">
                                                </div>
                                            </div>
                                            <div class="layui-inline">
                                                <label class="layui-form-label"></label>
                                                <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="Search">
                                                    搜索
                                                </button>
                                                <button class="layui-btn layui-btn-primary" id="Reset">
                                                    重置
                                                </button>

                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-card">
                        <div class="layui-card-body">
                            <a class="layui-btn " onclick="Add(null);">新增</a>
                            <div style="margin-top: 10px;" id="AutoTablediv">
                                <table class="layui-hide" style="width:100%" id="AutoTable" lay-filter="AutoTable"></table>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>



    </div>
</div>

<script type="text/html" id="EditOrAddHtml">
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">单表模式</li>
            <li>excel导入模式</li>

        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <div class="layui-card">
                    <div class="layui-card-body" style="padding: 15px;">
                        <form class="layui-form" lay-filter="AddForm" id="AddForm" autocomplete="off">
                            <input type="hidden" name="Id" class="layui-input">

                            <div class="layui-form-item">
                                <label class="layui-form-label">表名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="tbName" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">表描述</label>
                                <div class="layui-input-block">
                                    <input type="text" name="tbDes" class="layui-input" lay-verify="required">

                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">实体名</label>
                                <div class="layui-input-block">
                                    <input type="text" name="tbModelName" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">模板名</label>
                                <div class="layui-input-block">
                                    <select class="layui-input" name="templateNm" lay-verify="required">
                                        <option value="单表(增删改查)">单表(增删改查)</option>
                                        <option value="树表(增删改查)">树表(增删改查)</option>
                                        <option value="主子表(增删改查)">主子表(增删改查)</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">表格按钮</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="edit" value="edit" title="修改" lay-skin="primary">
                                    <input type="checkbox" name="edit" value="editp" title="需要权限" lay-skin="primary">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label" style="visibility:hidden">按钮配置</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="del" title="删除" lay-skin="primary" value="del">

                                    <input type="checkbox" name="del" value="delp" title="需要权限" lay-skin="primary">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">页面按钮</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="Add" value="Add" title="新增" lay-skin="primary">
                                    <input type="checkbox" name="Add" value="Addp" title="需要权限" lay-skin="primary">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label" style="visibility:hidden">页面按钮</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="DelAll" value="DelAll" title="批量删除" lay-skin="primary">
                                    <input type="checkbox" name="DelAll" value="DelAllp" title="需要权限" lay-skin="primary">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label" style="visibility:hidden">页面按钮</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="exportEx" value="ExportExcel" title="导出" lay-skin="primary">
                                    <input type="checkbox" name="exportEx" value="ExportExcelp" title="需要权限" lay-skin="primary">
                                </div>
                            </div>

                            <div class="layui-form-item" style="text-align:center;">
                                <button class="layui-btn" lay-filter="SaveBtn" lay-submit>保存</button>
                                <button class="layui-btn layui-btn-primary" type="button" id="SaveCancel">取消</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <div class="layui-tab-item">
                <!--excel导入页面-->
                <div class="layui-form-item" style="text-align:center;">
                    <a class="layui-btn " onclick="TemplateDownload();">模板下载</a>
                    <input type="file" onchange="ImportData()" name="导入配置" id="filesupload" accept=".xls,.xlsx" />
                    <!--<a class="layui-btn " onclick="ImportData();">导入配置</a>-->


                    <button class="layui-btn layui-btn-primary" type="button" id="SaveCancel">取消</button>
                </div>
            </div>

        </div>
    </div>

</script>


<script type="text/html" id="EditColHtml">
    <div class="layui-card">
        <table class="layui-hide" style="width:100%;" id="ColCfgTable" lay-filter="ColCfgTable"></table>
    </div>
    <form class="layui-form" lay-filter="ColCfgForm" id="ColCfgForm" autocomplete="off">
        <div class="layui-form-item" style="text-align:right;">
            <button class="layui-btn" lay-filter="SaveCol" lay-submit>保存</button>
            <button class="layui-btn layui-btn-primary" type="button" id="ColCancel">取消</button>
        </div>
    </form>
</script>
<script type="text/html" id="dicTypeTemp">
    <select class="layui-input" name="dicTy" id="dicTy" lay-verify="required" data-dataindex="{{d.LAY_TABLE_INDEX}}" lay-filter="dicTy" lay-value={{d.dicTy}} value={{d.dicTy}}>
    </select>
</script>

<script type="text/html" id="searchTemp">
    <select class="layui-input" name="searchTy" id="searchTy" lay-verify="required" data-dataindex="{{d.LAY_TABLE_INDEX}}" lay-filter="searchTy" lay-value={{d.searchTy}} value={{d.searchTy}}>
        <option value="请选择">请选择</option>
        {{# if(d.searchTy=="=") {}}
        <option value="=" selected>=</option>
        {{# } else{ }}
        <option value="=">=</option>
        {{# } }}

        {{# if(d.searchTy=="!=") {}}
        <option value="!=" selected>!=</option>
        {{# } else{ }}
        <option value="!=">!=</option>
        {{# } }}

        {{# if(d.searchTy==">") {}}
        <option value=">" selected>></option>
        {{# } else{ }}
        <option value=">">></option>
        {{# } }}

        {{# if(d.searchTy==">=") {}}
        <option value=">=" selected>>=</option>
        {{# } else{ }}
        <option value=">=">>=</option>
        {{# } }}

        {{# if(d.searchTy=="<") {}}
        <option value="<" selected><</option>
        {{# } else{ }}
        <option value="<"><</option>
        {{# } }}

        {{# if(d.searchTy=="<=") {}}
        <option value="<=" selected><=</option>
        {{# } else{ }}
        <option value="<="><=</option>
        {{# } }}

        {{# if(d.searchTy=="Like") {}}
        <option value="Like" selected>Like</option>
        {{# } else{ }}
        <option value="Like">Like</option>
        {{# } }}

        {{# if(d.searchTy=="Between") {}}
        <option value="Between" selected>Between</option>
        {{# } else{ }}
        <option value="Between">Between</option>
        {{# } }}
    </select>
</script>

<script type="text/html" id="showTemp">
    <select class="layui-input" name="showTy" id="showTy" lay-verify="required" lay-filter="showTy" lay-value={{d.showTy}} value={{d.showTy}}>
        <option value="请选择">请选择</option>
        {{# if(d.showTy=="文本框") {}}
        <option value="文本框" selected>文本框</option>
        {{# } else{}}
        <option value="文本框">文本框</option>
        {{# } }}

        {{# if(d.showTy=="本文域") {}}
        <option value="本文域" selected>本文域</option>
        {{# } else{}}
        <option value="本文域">本文域</option>
        {{# } }}

        {{# if(d.showTy=="下拉框") {}}
        <option value="下拉框" selected>下拉框</option>
        {{# } else{}}
        <option value="下拉框">下拉框</option>
        {{# } }}
        {{# if(d.showTy=="图片控件") {}}
        <option value="图片控件" selected>图片控件</option>
        {{# } else{}}
        <option value="图片控件">图片控件</option>
        {{# } }}

        {{# if(d.showTy=="单选框") {}}
        <option value="单选框" selected>单选框</option>
        {{# } else{}}
        <option value="单选框">单选框</option>
        {{# } }}

        {{# if(d.showTy=="复选框") {}}
        <option value="复选框" selected>复选框</option>
        {{# } else{}}
        <option value="复选框">复选框</option>
        {{# } }}

        {{# if(d.showTy=="富文本") {}}
        <option value="富文本" selected>富文本</option>
        {{# } else{}}
        <option value="富文本">富文本</option>
        {{# } }}

        {{# if(d.showTy=="日期控件") {}}
        <option value="日期控件" selected>日期控件</option>
        {{# } else{}}
        <option value="日期控件">日期控件</option>
        {{# } }}

        {{# if(d.showTy=="上传控件") {}}
        <option value="上传控件" selected>上传控件</option>
        {{# } else{}}
        <option value="上传控件">上传控件</option>
        {{# } }}
        {{# if(d.showTy=="多选下拉框") {}}
        <option value="多选下拉框" selected>多选下拉框</option>
        {{# } else{}}
        <option value="多选下拉框">多选下拉框</option>
        {{# } }}
    </select>
</script>

<script type="text/html" id="insertTemp">
    <input type="checkbox" name="isInsert" value="{{d.isInsert}}" lay-skin="switch" lay-text="是|否" lay-filter="isInsert" {{ d.isInsert == true ? 'checked' : '' }}>

</script>
<script type="text/html" id="editTemp">
    <input type="checkbox" name="isEdit" value="{{d.isEdit}}" lay-skin="switch" lay-text="是|否" lay-filter="isEdit" {{ d.isEdit == true ? 'checked' : '' }}>

</script>
<script type="text/html" id="listTemp">
    <input type="checkbox" name="isList" value="{{d.isList}}" lay-skin="switch" lay-text="是|否" lay-filter="isList" {{ d.isList == true ? 'checked' : '' }}>

</script>
<script type="text/html" id="issearchTemp">
    <input type="checkbox" name="isSearch" value="{{d.isSearch}}" lay-skin="switch" lay-text="是|否" lay-filter="isSearch" {{ d.isSearch == true ? 'checked' : '' }}>

</script>
<script type="text/html" id="biTianTemp">
    <input type="checkbox" name="biTian" value="{{d.biTian}}" lay-skin="switch" lay-text="是|否" lay-filter="biTian" {{ d.biTian == true ? 'checked' : '' }}>

</script>

<style>
    td .layui-form-select {
        margin-top: -10px;
        margin-left: -15px;
        margin-right: -15px;
    }
</style>

<script src="/Scripts/common.js?v=4"></script>
<script>
    var tableId = null,
        treeGrid = null,
        layer = null,
        upload = null,
        table = null,
        element = null,
        $ = null,
        util = null,
        form = null,
        webUploader = null,
        uplaod = null,
        mouseRightMenu = null
    formSelects = null
    roles = []
    laydate = null;

    //获取 字典类型
    var dictNameOptions = new Array();
    function TemplateDownload() {
        window.open('/template/AutoCreateCode.xlsx');
    }
    function ImportData() {
        $("#files").click()
        var formData = new FormData();
        formData.append("formfile", document.getElementById("filesupload").files[0]);
        debugger
        $.ajax({
            url: "/SysAutoCreateCodeCfg/ImportData",
            dataType: 'json',
            type: 'POST',
            async: false,
            data: formData,
            beforeSend: function (XMLHttpRequest) {
                //showLoading();
                setHeader(XMLHttpRequest)
            },
            processData: false, // 使数据不做处理
            contentType: false, // 不要设置Content-Type请求头
            success: function (res) {
                if (res.code == 0) {
                    layer.msg("导入完成！", {
                        icon: 1
                    });
                    layer.close(AddPaperindex);
                }
            }
        })
    }



    layui.use(
        ["layer", "element", 'laytpl', "util", "form", "jquery", "treeGrid", "upload", "table", "formSelects", "laydate"],
        function () {
            $ = layui.jquery;
            layer = layui.layer;
            element = layui.element;
            util = layui.util;
            form = layui.form;
            treeGrid = layui.treeGrid;
            upload = layui.upload;
            table = layui.table;
            formSelects = layui.formSelects
            laydate = layui.laydate;
            form.render()
            initDicTps();//获取字典类型数据源

            tableId = "AutoTable";
            table.render({
                elem: '#' + tableId,
                url: '/SysAutoCreateCodeCfg/GetList',
                method: 'post',
                headers: setTableHeader(),
                contentType: "application/json",
                autoColumnWidth: {
                    init: true
                },
                dataType: "json",

                //toolbar: '#selectProduct-table-toolbar',
                cols: [
                    [
                        {
                            field: 'Id',
                            hide: true,
                            align: 'center',
                            title: "会话标识"
                        },
                        {
                            field: 'tbName',
                            align: 'center',
                            title: "表名称"
                        },
                        {
                            field: 'tbDes',
                            align: 'center',
                            title: "表描述"
                        },
                        {
                            field: 'tbModelName',
                            align: 'center',
                            title: "实体名"
                        }, {
                            field: 'templateNm',
                            align: 'center',
                            title: "模板名"
                        },
                        {
                            field: 'createOn',
                            align: 'center',
                            width: 160,
                            title: "创建时间"
                        }, {
                            field: 'createBy',
                            align: 'center',
                            width: 120,
                            title: "创建人",
                        },
                        {
                            title: '操作',
                            align: 'center',
                            templet: function (d) {
                                var html = '';
                                html += '<a class="layui-btn layui-btn-xs" lay-event="edit" style="margin-right: 10px;">编辑</a>';
                                html += '<a class="layui-btn layui-btn-xs" lay-event="editCol" style="margin-right: 10px;">编辑列配置</a>';

                                html += '<a class="layui-btn layui-btn-xs" lay-event="createCode" style="margin-right: 10px;">生成代码</a>';
                                html += '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" style="margin-right: 10px;"> 删除</a>';

                                return html;
                            }
                        }
                    ]
                ],
                page: true,
                where: {
                    dt: new Date()
                },
                done: function (res, curr, count) {

                    //  $("[data-field='userId']").css('display', 'none');

                }
            });


            table.on('tool(' + tableId + ')', function (obj) {
                //console.log(obj);
                if (obj.event == "edit") {
                    Add(obj.data);
                }
                else if (obj.event == "del") {
                    layer.confirm("是否删除该记录？", {
                        btn: ['确认', '取消']
                    }, function () {
                        ajax("/SysAutoCreateCodeCfg/Delete?id=" + obj.data.Id, "get", "Json", {}, function (res) {
                            if (res.code == 0) {
                                obj.del();
                                layer.msg('删除成功！', {
                                    icon: 1
                                });
                                //table.reload(tableId, {
                                //    where: {
                                //        dt: new Date()
                                //    }
                                //});
                            }
                        });
                    }, function (index) {
                        layer.close(index);
                    });
                }
                else if (obj.event == "createCode") {
                    layer.confirm("确定要生成代码么？", {
                        btn: ['确认', '取消']
                    }, function () {
                        ajax("/SysAutoCreateCodeCfg/AutoCreateCode?id=" + obj.data.Id, "get", "Json", {}, function (res) {
                            if (res.code == 0) {
                                layer.msg('生成成功！', {
                                    icon: 1
                                });
                                //table.reload(tableId, {
                                //    where: {
                                //        dt: new Date()
                                //    }
                                //});
                                location.href = res.msg;
                                return false
                            }
                        });
                    }, function (index) {
                        layer.close(index);
                    });
                }
                else if (obj.event == "editCol") {
                    EditCol(obj.data)
                }
            });


            form.on('submit(Search)', function (data) {
                //console.log(data.field);

                //执行重载
                table.reload(tableId, {
                    page: {
                        curr: 1 //重新从第 1 页开始

                    },
                    where: data.field
                }, 'data');

                return false;
            });


            //编辑页面提交
            form.on('submit(SaveBtn)', function (data) {
                var json = $("#AddForm").serializeObject();

                // 保存按钮配置
                var BtnActionLst = new Array();
                var edit = new Object();
                var del = new Object();
                var Add = new Object();
                var DelAll = new Object();
                var exportEx = new Object();
                $('input[name=edit]:checked').each(function () {
                    var val = $(this).val()
                    edit.IsPermission = false
                    if (val == "edit") {
                        edit.BtnName = val
                    }
                    if (val == "editp" && edit != null) {
                        edit.IsPermission = true
                    }


                });
                $('input[name=del]:checked').each(function () {

                    var val = $(this).val()
                    del.IsPermission = false
                    if (val == "del") {
                        del.BtnName = val
                    }
                    if (val == "delp" && edit != null) {
                        del.IsPermission = true
                    }


                });
                $('input[name=Add]:checked').each(function () {

                    var val = $(this).val()
                    Add.IsPermission = false
                    if (val == "Add") {
                        Add.BtnName = val
                    }
                    if (val == "Addp" && edit != null) {
                        Add.IsPermission = true
                    }


                });
                $('input[name=DelAll]:checked').each(function () {

                    var val = $(this).val()
                    DelAll.IsPermission = false
                    if (val == "DelAll") {
                        DelAll.BtnName = val
                    }
                    if (val == "DelAllp" && edit != null) {
                        DelAll.IsPermission = true
                    }


                });
                $('input[name=exportEx]:checked').each(function () {

                    var val = $(this).val()
                    exportEx.IsPermission = false
                    if (val == "ExportExcel") {
                        exportEx.BtnName = val
                    }
                    if (val == "ExportExcelp" && edit != null) {
                        exportEx.IsPermission = true
                    }

                });
                if (edit.BtnName != undefined) { BtnActionLst.push(edit); }
                if (del.BtnName != undefined) { BtnActionLst.push(del); }

                if (Add.BtnName != undefined) { BtnActionLst.push(Add); }
                if (DelAll.BtnName != undefined) { BtnActionLst.push(DelAll); }
                if (exportEx.BtnName != undefined) { BtnActionLst.push(exportEx); }
                // end
                debugger
                //for (var i in btns) {
                //    console.log(btns[i]); //遍历选中的值
                //}
                json.BtnActionLst = BtnActionLst
                console.log(json);
                debugger

                ajax("/SysAutoCreateCodeCfg/SaveOrEdit", "post", "json", JSON.stringify(json), function (res) {
                    if (res.code == 0) {
                        layer.close(AddPaperindex);
                        table.reload(tableId,
                            {
                                where: {
                                    dt: new Date()
                                }
                            });
                    }
                }, "application/json");

                return false;
            })


            //重置
            $(document).on("click", "#Reset", function () {
                $("#AutoCodeSearchForm")[0].reset();
                form.render(null, "AutoCodeSearchForm");
                return false;
            });

            function initDicTps() {
                ajax("/SysDictionaryTypeModel/GetDicTpDropLst", "get", "Json", {}, function (res) {
                    if (res.code == "0") {

                        for (var k = 0; k < res.data.length; k++) {

                            dictNameOptions.push(res.data[k])
                        }
                    }

                    return false;
                }, "application/json", true);
            }
        });



    var AddPaperindex;
    function Add(data) {
        AddPaperindex = layer.open({
            type: 1,
            title: "编辑表配置",
            content: $("#EditOrAddHtml").html(),
            area: ['700px', 'auto'],
            //btn: ["保存", "取消"],
            success: function (layero, dIndex) {
                //解决下拉框显示被遮盖的问题
                $(layero).children(".layui-layer-content").css("overflow", "visible").css("height", "auto");

                form.render("select");
                form.val("AddForm", data);
                if (data == null) {
                    //如果是新增，则重置form
                    document.getElementById("AddForm").reset(); //
                }
                //alert(JSON.stringify(data));
                //form.render(); // 更新AddTestPaperForm内的所有表单状态
            }

        });

        //取消
        $(document).on("click", "#SaveCancel", function () {
            layer.close(AddPaperindex);
        });
    }

    //$(document).on("click", "#ColCancel", function () {
    //    layer.close(EditColIndex);
    //});

    function EditCol(data) {
        layui.use(
            ["layer", "form", "jquery", "upload", "table", "formSelects", "laydate"],
            function () {

                var form2 = layui.form;
                var table2 = layui.table;
                //弹出编辑列的窗口

                var EditColIndex;

                EditColIndex = layer.open({
                    type: 1,
                    title: "编辑列配置",
                    content: $("#EditColHtml").html(),
                    area: ['80%', '80%'],
                    //btn: ["保存", "取消"],
                    success: function (layero, dIndex) {
                        //列配置
                        table2.render({
                            elem: '#ColCfgTable',
                            url: '/SysAutoCreateCodeCfg/GetColList?id=' + data.Id,
                            method: 'get',
                            headers: setTableHeader(),
                            contentType: "application/json",
                            dataType: "json",

                            //toolbar: '#selectProduct-table-toolbar',
                            cols: [
                                [
                                    {
                                        field: 'Id',
                                        hide: true,
                                        title: "会话标识"
                                    },
                                    {
                                        field: 'tbName',
                                        hide: true,
                                        align: 'center',
                                        title: "表名称"
                                    },
                                    {
                                        field: 'colName',
                                        align: 'center',
                                        title: "字段列名"
                                    },
                                    {
                                        field: 'colDes',
                                        align: 'center',
                                        title: "字段描述",
                                        edit: true
                                    }, {
                                        field: 'colType',
                                        align: 'center',
                                        title: "数据类型"
                                    },
                                    {
                                        field: 'netType',
                                        align: 'center',
                                        edit: true,
                                        title: "C#类型"
                                    }, {
                                        field: 'isInsert',
                                        align: 'center',
                                        templet: '#insertTemp',
                                        title: "插入",
                                    }, {
                                        field: 'isEdit',
                                        align: 'center',
                                        templet: '#editTemp',
                                        title: "编辑",
                                    }, {
                                        field: 'isList',
                                        align: 'center',
                                        templet: '#listTemp',
                                        title: "列表",
                                    }, {
                                        field: 'isSearch',
                                        align: 'center',
                                        templet: '#issearchTemp',
                                        title: "查询",
                                    }, {
                                        field: 'searchTy',
                                        align: 'center',
                                        templet: '#searchTemp',
                                        title: "查询方式",
                                    }, {
                                        field: 'biTian',
                                        align: 'center',
                                        templet: '#biTianTemp',
                                        title: "必填",
                                    }, {
                                        field: 'showTy',
                                        align: 'center',
                                        templet: '#showTemp',
                                        title: "显示类型",
                                    }, {
                                        field: 'dicTy',
                                        align: 'center',
                                        type: 'select',
                                        templet: function (d) {
                                            var options = "<option value=''>请选择</option>\n";
                                            if (d.dicTy == null) {
                                                for (var m = 0; m < dictNameOptions.length; m++) {
                                                    options += "<option value='" + dictNameOptions[m].ItemCode + "'  >" + dictNameOptions[m].ItemName + "</option>\n";

                                                }
                                            }
                                            else {
                                                for (var m = 0; m < dictNameOptions.length; m++) {
                                                    if (d.dicTy == dictNameOptions[m].ItemCode) {
                                                        options += "<option value='" + dictNameOptions[m].ItemCode + "' selected>" + dictNameOptions[m].ItemName + "</option>\n";
                                                    } else {
                                                        options += "<option value='" + dictNameOptions[m].ItemCode + "'  >" + dictNameOptions[m].ItemName + "</option>\n";

                                                    }
                                                }
                                            } debugger
                                            return "<select id='dicTy' name='dicTy'  lay-filter='dicTy'>" + options + "</select>"
                                        },
                                        title: "字典类型"
                                    }, {
                                        field: 'sort',
                                        align: 'center',
                                        title: "排序",
                                        edit: true
                                    }
                                    //{
                                    //    title: '操作',
                                    //    align: 'center',
                                    //    templet: function (d) {

                                    //    }
                                    //}
                                ]
                            ],

                            where: {
                                dt: new Date()
                            },
                            done: function (res, curr, count) {
                                //var colDatas = res.data //遍历表数据
                                //var options = "<option value=''>请选择</option>";
                                ////如果等于源数据 则选中
                                //for (var m = 0; m < dictNameOptions.length; m++) {
                                //    options += "<option value='" + dictNameOptions[m].ItemCode + "'>" + dictNameOptions[m].ItemName + "</option>";

                                //}
                                //debugger
                                ////for (var k = 0; k < colDatas.length; k++) {
                                ////    //如果等于源数据 则选中
                                ////    for (var m = 0; m < dictNameOptions.length; m++) {

                                ////        if (colDatas[k].dicTy == dictNameOptions[m].ItemCode) {
                                ////            options += "<option value='" + dictNameOptions[m].ItemCode + "' selected>" + dictNameOptions[m].ItemName + "</option>";
                                ////        } else {
                                ////            options += "<option value='" + dictNameOptions[m].ItemCode + "'>" + dictNameOptions[m].ItemName + "</option>";

                                ////        }
                                ////    }
                                ////}
                                ////debugger
                                //$("select[name='dicTy']").html(options);
                                //layui.each($("select[name='dicTy']"), function (index, item) {
                                //    var elem = $(item);
                                //    debugger
                                //    elem.val(elem.data('value'));
                                //});


                                form2.render('select');//重新渲染
                                //显示下拉框
                                $(".layui-table-body, .layui-table-box, .layui-table-cell").css('overflow', 'visible');
                            }

                        });

                        //显示字典类型 赋值到table
                        setDropList("dicTy")
                        //查询方式下拉 赋值到table
                        setDropList("searchTy")
                        //显示类型 赋值到table
                        setDropList("showTy")



                        //是否是插入字段 赋值到table
                        setCheckbox("isInsert");
                        //是否是编辑字段 赋值到table
                        setCheckbox("isEdit");
                        //是否再列表中显示 赋值到table
                        setCheckbox("isList");
                        //是否是筛选条件 赋值到table
                        setCheckbox("isSearch");
                        //是否是必填 赋值到table
                        setCheckbox("biTian");

                    }
                });

                //checkbox 改变后 赋值给table
                function setCheckbox(tyName) {
                    form2.on('switch(' + tyName + ')', function (data) {
                        var elem = data.othis.parents('tr');
                        var dataindex = elem.attr("data-index");
                        var tabledata = table.cache["ColCfgTable"];
                        $.each(tabledata, function (index, value) {
                            if (value.LAY_TABLE_INDEX == dataindex) {
                                tabledata[index]["" + tyName + ""] = data.elem.checked;

                            }
                        })
                    });
                }
                //修改下拉框数据 绑定table
                function setDropList(listName) {
                    form2.on('select(' + listName + ')', function (data) {
                        debugger
                        var elem = data.othis.parents('tr');
                        var dataindex = elem.attr("data-index");
                        var tabledata = table.cache["ColCfgTable"];
                        $.each(tabledata, function (index, value) {
                            debugger
                            if (value.LAY_TABLE_INDEX == dataindex) {
                                tabledata[index]["" + listName + ""] = data.value;

                            }
                        })
                    });
                }

                //保存列配置
                form2.on('submit(ColCfgForm)', function (data) {
                    debugger
                    var data = table2.cache["ColCfgTable"];

                    ajax("/SysAutoCreateCodeCfg/SaveColConfig", "post", "json", JSON.stringify(data), function (res) {
                        if (res.code == 0) {
                            layer.close(EditColIndex)
                        }
                    }, "application/json");

                    return false;
                })



                $(document).on("click", "#ColCancel", function () {
                    layer.close(EditColIndex);
                });
            });
    }</script>
